package com.letoken.platform.repo.mall.dao;

import com.letoken.platform.pub.annotation.sms.SpecifyMatch;
import com.letoken.platform.repo.mall.po.AppMallInfo;
import com.letoken.platform.repo.mall.po.AppMallOrderInfo;
import com.letoken.platform.repo.mall.po.AppMallStatistics;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.swagger.annotations.ApiModelProperty;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 店铺统计数据 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2023-04-21
 */
public interface AppMallStatisticsMapper extends BaseMapper<AppMallStatistics> {


    void updateBatchByMallId(@Param("list")List<AppMallStatistics> list);


    @Select("select * from app_mall_statistics where mall_id = #{mallId}")
    AppMallStatistics selectByMallId(@Param("mallId") Integer mallId);


    @Select("select count(1) from app_mall_info  where state = 1 ")
    Integer staticStoreNumber();

    @Select("select sum(amount) from app_mall_order_info ")
    BigDecimal staticStoreTurnover();

    @Select("select IFNULL(sum(balance),0) from app_mall_account ")
    BigDecimal staticStoreBalance();

    @Select("select count(1) from app_mall_info where state = 1 and is_business = 1")
    Integer staticStoreEnterpriseNum();

    @Select("select count(1) from app_mall_info where state = 1 and is_business = 0 ")
    Integer staticStorePersonal();


    @Select("select count(1) from app_mall_order_info where mall_id = #{mallId} and create_time >= #{startTime} and create_time < #{endTime}")
    Integer yesOrderNum(@Param("mallId") Integer mallId, @Param("startTime")LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);

    @Select("select sum(amount*contributing) from app_mall_order_info where mall_id = #{mallId} and create_time >= #{startTime} and create_time < #{endTime}")
    BigDecimal yesContribut(@Param("mallId") Integer mallId, @Param("startTime")LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);

    @Select("select sum(amount) from app_mall_order_info where mall_id = #{mallId} and create_time >= #{startTime} and create_time < #{endTime}")
    BigDecimal yesTurnover(@Param("mallId") Integer mallId, @Param("startTime")LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);


}
